CFLAGS=-Wall
#CFLAGS+=-Wextra
CFLAGS+=-O2
CFLAGS+=-g
CFLAGS_MSP430=-mmcu=msp430x1611 -DON_PC=0 -mnoint-hwmul


all: exact-imp wqrs msp430 senddata
	

OBJS=exact-imp.o validation.o profiler.o

exact-imp: $(OBJS) Makefile
	gcc $(CFLAGS) $(OBJS) -o exact-imp -lm

exact-imp.o: exact-imp.c validation.h Makefile
	gcc $(CFLAGS) -c exact-imp.c

validation.o: validation.c validation.h Makefile
	gcc $(CFLAGS) -c validation.c

profiler.o: profiler.c profiler.h Makefile
	gcc $(CFLAGS) -c profiler.c

wqrs: wqrs.c Makefile
	gcc $(CFLAGS) wqrs.c -o wqrs -I../usr/include -L../usr/lib -lwfdb -lm

senddata.o: senddata.c Makefile
	gcc $(CFLAGS) -c senddata.c

senddata: senddata.o validation.o Makefile
	gcc $(CFLAGS) validation.o senddata.o -o senddata -lm

program-msp430: msp430
	msp430-bsl -S 38400 --invert-test --invert-reset -e -r -I -c /dev/ttyUSB0 -p exact-imp-msp430.hex

msp430:	exact-imp-msp430.hex
	

exact-imp-msp430.elf: exact-imp.c validation.h Makefile profiler.c profiler.h
	msp430-gcc $(CFLAGS) $(CFLAGS_MSP430) -o exact-imp-msp430.elf exact-imp.c profiler.c

exact-imp-msp430.hex: exact-imp-msp430.elf Makefile
	msp430-objcopy -O ihex exact-imp-msp430.elf exact-imp-msp430.hex

clean:
	rm -f exact-imp wqrs *~ *.o exact-imp-msp430.hex exact-imp-msp430.elf

.PHONY: clean, gprof
